$(document).ready(function() {
    $.history.init(function(hash){
        if(hash != "") {                       
            if (typeof(waitingDiv)=='undefined') waitingDiv = new waiting();
            waitingDiv.load(document.getElementById("main_content"), {
                waitingGif: false
            });
            var clearedHashArray = hash.match(/([^/]*)\/?/);
            var clearedHash = hash;    
            if (clearedHashArray)
                clearedHash = clearedHashArray[1];    
            $('#left_navigation a').removeClass('active');
            $('a[href="#' + clearedHash + '"]').addClass('loading');
            $("#main_content").load('/admins/' + hash, function(){
                waitingDiv.hide();
                $('#left_navigation a').removeClass('loading');
                $('a[href="#' + clearedHash + '"]').addClass('active');
            }); 	
        }
        return false;
    });
    $('#left_navigation a').click(function(event){
        if ($(this).hasClass('active')){
            var parsed = this.href.match(/.+#(.+)$/);
            var href = (parsed[1])?(parsed[1]):('');
            if (href!=''){
                window.location = '#';
            }
        }
    });
    $('#logout').click(function(){
        window.location = this.href;
        return false;
    });
    $('#home').click(function(){
        window.location = this.href;
        return false;
    });
});